package e.odbo.interceptor;

import com.openbravo.data.loader.dataset.DataResultSet;
import com.openbravo.data.loader.sentence.I_DBExecInterceptor;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;

import java.util.Map;

public class JSqlParserExecInterceptor implements I_DBExecInterceptor {
    @Override
    public String interceptorExecBefore(String sentenceSql) {
        try {
            CCJSqlParserUtil.parse(sentenceSql);
        } catch (JSQLParserException e) {
            e.printStackTrace();
        }
        return sentenceSql;
    }

    @Override
    public Map.Entry<String, Object> interceptorExecPreparedBefore(final String sql, final Object paras) {
        try {
            CCJSqlParserUtil.parse(sql);
        } catch (JSQLParserException e) {
            e.printStackTrace();
        }

        return new Map.Entry<String, Object>(){

            @Override
            public String getKey() {
                return sql;
            }

            @Override
            public Object getValue() {
                return paras;
            }

            @Override
            public Object setValue(Object value) {
                return null;
            }
        };
    }

    @Override
    public void interceptorAfter(DataResultSet dataResultSet) {

    }

}
